package com.smart.parking.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smart.parking.entity.LoginLogEntity;
import com.smart.parking.mapper.LoginLogMapper;
import com.smart.parking.service.LoginLogService;
import com.smart.parking.utils.PageUtils;
import com.smart.parking.utils.Query;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Date;
import java.util.List;
import java.util.Map;


@Service("loginLogService")
public class LoginLogServiceImpl extends ServiceImpl<LoginLogMapper, LoginLogEntity> implements LoginLogService {

    @Autowired
    private Mapper dozerMapper;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<LoginLogEntity> page = this.page(
                new Query<LoginLogEntity>().getPage(params),
                new QueryWrapper<LoginLogEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 添加登录日志
     *
     * @param userId 用户id
     */
    @Override
    public void addLoginLog(Long userId, Date loginTime) {
        LoginLogEntity loginLogEntity = new LoginLogEntity();
        loginLogEntity.setUserId(userId);
        loginLogEntity.setLoginTime(loginTime);
        baseMapper.insert(loginLogEntity);
    }

    /**
     * 查询本用户登录日志
     */
    @Override
    public List<LoginLogEntity> getLoginLogList(Long userId) {
        return baseMapper.selectList(new QueryWrapper<LoginLogEntity>().eq("user_id", userId));
    }

    /**
     * 超级管理查询所有用户登录信息
     */
    @Override
    public List<LoginLogEntity> getLoginLogLists() {
        return baseMapper.selectList(null);
    }

}
